package com.tank;

import java.awt.*;
import java.awt.image.BufferedImage;

/**
 * @author CaoBaoYin
 * @since 2021/8/20 20:25
 */
public class ImageUtil {

    public static BufferedImage rotateImage (final BufferedImage image, final int degree) {
        int width = image.getWidth();
        int height = image.getHeight();
        int type = image.getColorModel().getTransparency();
        BufferedImage bufferedImage = new BufferedImage(width, height, type);
        Graphics2D graphics2D = bufferedImage.createGraphics();
        graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
        graphics2D.rotate(Math.toRadians(degree), width/2, height/2);
        graphics2D.drawImage(image, 0, 0, null);
        graphics2D.dispose();
        return bufferedImage;
    }

}
